
var _domain = 'http://demo.yeahyo.cn/test/qqbrowser/2018novel/';// 授权回调地址
var _auth_url = 'http://migmkt.qq.com/g/act/auth.html';//授权url
var _token = 'H8L9gvuv0XZWcMGRNBG9s/HGDuN8sN2x0SgOyuxUykmYfg7c4gu8HIyB4cJsU3L3';//授权token参数
var _cookie_name = 'tx_cookie2';
var _nickname = GetQueryString('nickname') ? GetQueryString('nickname') : $.cookie(_cookie_name) ? JSON.parse($.cookie(_cookie_name)) : false;
// getUserInfo();
function getUserInfo() {
	if (!_nickname) {
		window.location.href = _auth_url + '?type=qb&token=' + _token + '&ref=' + encodeURIComponent(_domain);
		return;
	}
	$.cookie(_cookie_name, JSON.stringify(_nickname), { expires: 365, path: '/' });
	//alert(_nickname);
	console.log(_nickname);
	return;
}
function GetQueryString(key) {
	var url = window.location.search;
	var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");// 正则筛选地址栏   
	var result = url.substr(1).match(reg); // 匹配目标参数   
	return result ? decodeURIComponent(result[2]) : null;
}


(function () {
	var _options = {
		appKeys: 'wxea8465c8c15263f0',
		call: function () {
			console.log('授权成功!');
			var oid = wxAuth.cookies.get(_options.cookieConfig.id);
			var head = wxAuth.cookies.get(_options.cookieConfig.head);
			var nickname = wxAuth.cookies.get(_options.cookieConfig.name);
			if (oid && head && nickname) {
				callSuccess({ "headimgurl": head, "nickname": nickname, "openid": oid });
			} else {
				console.log(JSON.stringify({ "headimgurl": head, "nickname": nickname, "openid": oid }));
			}
		},
		authConfig: { url: '//service.mkt.qq.com/interface?interface_name=mktservice_qb_getuserinfo&interface_params={"code":"NEWCODE"}' },
		cookieConfig: { id: 'qbID', name: 'qbName', head: 'qbHead' }
	};

	function callSuccess(o) {
		o = o || {};
		_nickname = o.nickname;
	}

	var ua = navigator.userAgent.toLowerCase();//获取判断用的对象
	var wxopen = ua.match(/MicroMessenger/i) == "micromessenger";
	wxopen = GetQueryString("t");
	if (document.domain == 'migmkt.qq.com' && !wxopen) {
		wxAuth.auth.init(_options);
	}

})();